/**
 * @file tvwheel.c
 * @brief 时间轮实现，用一个线程代替大量的定时器，时间轮的关键设计是1:时间槽的个数；2一圈的时间长度(sec) ；3 支持的总轮数。在一个项目钟可以实例多个时间轮
 * @author ken (kangjiening@openvalley.net)
 * @version 0.1
 * @date 2023-06-07
 * 
 * @copyright Copyright (c) 2023  湖南开鸿智谷数字产业发展有限公司
 * 
 * @par 修改日志:
 *     @date 2023-06-07
 *     @version 0.2
 *     @author xx
 *     @brief xx
 */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "memory_adapter.h"
#include "innervent.h"
#include "tvwheel.h"
/**
 * @brief 创建时间轮
 * @param  wheelPower       时间轮总数
 * @param  wheelSize        单个轮上时间轮的槽数
 * @param  interval      时间轮的单个槽时间长度
 * @return struct TimeWheel*  时间轮的地址值
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-07
 */
struct TimeWheel  *TimeWheelCreate(uint32_t wheelPower,uint32_t wheelSize,uint32_t interval)
{
   
    struct TimeWheel *timeWheel = Event_Malloc(sizeof(struct TimeWheel));
    if(timeWheel == NULL ) return NULL;
    timeWheel->currentSlot = 0;
    timeWheel->wheelPower = wheelPower;
    timeWheel->interval = interval;
    timeWheel->wheelSize =  wheelSize;
    return timeWheel;

}
/**
 * @brief 插入时间节点,
 * @param  timeWheel        
 * @param  timeNode         
 * @param  timeOut         ms为单位  
 * @return int 
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-07
 */
int TimeWheelInsert(struct TimeWheel *timeWheel,struct InnerEvent *innerEvent,uint32_t timeOut )
{
    //if(timeOut > timeWheel->wheelPower*timeWheel->interval*timeWheel->wheelSize) return NULL;
    struct TimeNode *timeNode = Event_Malloc(sizeof(struct TimeNode));
    
    timeNode->while = timeout / (timeWheel->interval*timeWheel->wheelSize);
    timeNode->
    return 0;

}


/**
 * @brief 删除一个Node
 * @param  timeWheel        
 * @param  timeNode         
 * @return int 
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-07
 */
int TimeWheelDelete(struct TimeWheel *timeWheel,struct TimeNode *timeNode )
{
    return 0;
}
/**
 * @brief 这是一个handler
 * @param  timeWheel        
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-07
 */
void TimeWheelRun(struct TimeWheel *timeWheel)
{

}

/**
 * @brief 销毁整个时间轮
 * @param [in] timeWheel 
 * @return int 
 * 
 * @details 
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-14
 */
int TimewheelDestory(struct TimeWheel *timeWheel)
{
    return 0;
}

